﻿namespace WMS6.Web.Analytics
{
    using System;
    using System.Data;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.CustomsServiceRef;
    using WMS6.Web.UserControls;

    public class DeclarationsInOutDetailRptList : BasePage
    {
        protected Button btnExport;
        protected Button btnList;
        protected Button btnNewSearch;
        protected Button btnRefresh;
        protected Button btnReSearch;
        protected Label DeclarationsInOutDetailRpt;
        protected HtmlForm F15551;
        protected GridView gvDeclarationsInOutDetailRpt;
        protected HtmlInputHidden hdnActionID;
        protected HtmlInputHidden hdnFrom;
        protected HtmlInputHidden hdnQty;
        protected HtmlHead Head1;
        public decimal InQty;
        protected Label lblMsg;
        protected HtmlLink mycss;
        public decimal OtQty;
        protected Pager PagerFooter;
        protected ScriptManager ScriptManager1;
        public string strDeclarationsID;
        public string strSkuID;
        protected UpdatePanel up1;

        private void BindData2ImportDeclarationsRptList(DeclarationsInOutDetailRptQueryEntity declarationsInOutDetailRptQueryEntity)
        {
            this.PagerFooter.CurrentPage = int.Parse(declarationsInOutDetailRptQueryEntity.CurrentPage);
            DataSet ds = new DataSet();
            ds = CustomsServiceClientProxy.GetInstance().GetDeclarationsInOutDetailRptDataSet(declarationsInOutDetailRptQueryEntity);
            base.BindData2GridView(this.gvDeclarationsInOutDetailRpt, ds);
            if ((ds != null) && (ds.Tables.Count > 1))
            {
                this.PagerFooter.PageInfo = ds.Tables[1].Rows[0]["CurrentPage"].ToString() + " / " + ds.Tables[1].Rows[0]["TotalPagesCount"].ToString() + "&nbsp;&nbsp;&nbsp;共: " + ds.Tables[1].Rows[0]["TotalRecordsCount"].ToString();
                this.PagerFooter.TotalPages = int.Parse(ds.Tables[1].Rows[0]["TotalPagesCount"].ToString());
            }
        }

        protected void btnExport_Click(object sender, EventArgs e)
        {
            DeclarationsInOutDetailRptQueryEntity declarationsInOutDetailRptQueryEntity = this.GetDeclarationsInOutDetailRptQueryEntity();
            declarationsInOutDetailRptQueryEntity.IsGetAll = true;
            this.hdnActionID.Value = "Y";
            string currentPageIndex = declarationsInOutDetailRptQueryEntity.CurrentPage;
            declarationsInOutDetailRptQueryEntity.CurrentPage = "0";
            this.gvDeclarationsInOutDetailRpt.Columns[1].Visible = false;
            this.gvDeclarationsInOutDetailRpt.AllowSorting = false;
            this.BindData2ImportDeclarationsRptList(declarationsInOutDetailRptQueryEntity);
            this.hdnActionID.Value = "";
            this.gvDeclarationsInOutDetailRpt.ShowFooter = false;
            declarationsInOutDetailRptQueryEntity.IsGetAll = false;
            declarationsInOutDetailRptQueryEntity.CurrentPage = currentPageIndex;
            this.SetDeclarationsInOutDetailRptQueryEntity(declarationsInOutDetailRptQueryEntity);
            this.hdnActionID.Value = "";
            base.Export2Excel("DeclarationsInOutDetailRpt.xls", this.gvDeclarationsInOutDetailRpt);
        }

        protected void btnFirst_Click(object sender, EventArgs e)
        {
            DeclarationsInOutDetailRptQueryEntity declarationsInOutDetailRptQueryEntity = this.GetDeclarationsInOutDetailRptQueryEntity();
            declarationsInOutDetailRptQueryEntity.CurrentPage = "0";
            this.BindData2ImportDeclarationsRptList(declarationsInOutDetailRptQueryEntity);
        }

        protected void btnLast_Click(object sender, EventArgs e)
        {
            DeclarationsInOutDetailRptQueryEntity declarationsInOutDetailRptQueryEntity = this.GetDeclarationsInOutDetailRptQueryEntity();
            declarationsInOutDetailRptQueryEntity.CurrentPage = (this.PagerFooter.TotalPages - 1).ToString();
            this.BindData2ImportDeclarationsRptList(declarationsInOutDetailRptQueryEntity);
        }

        protected void btnList_Click(object sender, EventArgs e)
        {
            DeclarationsInOutDetailRptQueryEntity declarationsInOutDetailRptQueryEntity = this.GetDeclarationsInOutDetailRptQueryEntity();
            declarationsInOutDetailRptQueryEntity.DeclarationsID = "";
            declarationsInOutDetailRptQueryEntity.OwnerID = "";
            declarationsInOutDetailRptQueryEntity.SkuID = "";
            declarationsInOutDetailRptQueryEntity.CompanyDeclarationgsID = "";
            declarationsInOutDetailRptQueryEntity.VerificationFormID = "";
            declarationsInOutDetailRptQueryEntity.DeclarationsDate = "";
            this.BindData2ImportDeclarationsRptList(declarationsInOutDetailRptQueryEntity);
        }

        protected void btnNext_Click(object sender, EventArgs e)
        {
            DeclarationsInOutDetailRptQueryEntity declarationsInOutDetailRptQueryEntity = this.GetDeclarationsInOutDetailRptQueryEntity();
            if (int.Parse(declarationsInOutDetailRptQueryEntity.CurrentPage) < (this.PagerFooter.TotalPages - 1))
            {
                declarationsInOutDetailRptQueryEntity.CurrentPage = (int.Parse(declarationsInOutDetailRptQueryEntity.CurrentPage) + 1).ToString();
                this.BindData2ImportDeclarationsRptList(declarationsInOutDetailRptQueryEntity);
            }
        }

        protected void btnPrevious_Click(object sender, EventArgs e)
        {
            DeclarationsInOutDetailRptQueryEntity declarationsInOutDetailRptQueryEntity = this.GetDeclarationsInOutDetailRptQueryEntity();
            if (int.Parse(declarationsInOutDetailRptQueryEntity.CurrentPage) > 0)
            {
                declarationsInOutDetailRptQueryEntity.CurrentPage = (int.Parse(declarationsInOutDetailRptQueryEntity.CurrentPage) - 1).ToString();
                this.BindData2ImportDeclarationsRptList(declarationsInOutDetailRptQueryEntity);
            }
        }

        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            DeclarationsInOutDetailRptQueryEntity declarationsInOutDetailRptQueryEntityEntity = this.GetDeclarationsInOutDetailRptQueryEntity();
            this.BindData2ImportDeclarationsRptList(declarationsInOutDetailRptQueryEntityEntity);
        }

        private DeclarationsInOutDetailRptQueryEntity GetDeclarationsInOutDetailRptQueryEntity()
        {
            if (!string.IsNullOrEmpty(this.hdnActionID.Value))
            {
                return (base.PageQueryEntityViewState as DeclarationsInOutDetailRptQueryEntity);
            }
            return (base.PageQueryEntitySession as DeclarationsInOutDetailRptQueryEntity);
        }

        protected void GoTo_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(((TextBox) this.PagerFooter.FindControl("txtGo2Page")).Text.Trim()))
            {
                DeclarationsInOutDetailRptQueryEntity declarationsInOutDetailRptQueryEntity = this.GetDeclarationsInOutDetailRptQueryEntity();
                declarationsInOutDetailRptQueryEntity.CurrentPage = this.PagerFooter.GoToPage.ToString();
                this.BindData2ImportDeclarationsRptList(declarationsInOutDetailRptQueryEntity);
            }
        }

        protected void gvDeclarationsInOutDetailRpt_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = (((this.PagerFooter.CurrentPage * this.PagerFooter.PageSize) + e.Row.RowIndex) + 1).ToString();
                e.Row.Attributes.Add("onmouseout", "GridViewRowMouseout(this);");
                e.Row.Attributes.Add("onmouseover", "GridViewRowMouseover(this);");
                ((CheckBox) e.Row.FindControl("chbSelect")).Attributes.Add("onclick", "GridViewCheckBoxClick('" + e.Row.ClientID + "')");
                base.SetGridViewLongTextLabel((Label) e.Row.FindControl("lblSkuDescr"));
                base.SetGridViewLongTextLabel((Label) e.Row.FindControl("lblItemNoDescr"));
            }
        }

        protected void gvDeclarationsInOutDetailRpt_Sorting(object sender, GridViewSortEventArgs e)
        {
            try
            {
                DeclarationsInOutDetailRptQueryEntity declarationsInOutDetailRptQueryEntity = this.GetDeclarationsInOutDetailRptQueryEntity();
                declarationsInOutDetailRptQueryEntity.SortField = e.SortExpression;
                if (declarationsInOutDetailRptQueryEntity.SortDirection == "ASC")
                {
                    declarationsInOutDetailRptQueryEntity.SortDirection = "DESC";
                }
                else if (declarationsInOutDetailRptQueryEntity.SortDirection == "DESC")
                {
                    declarationsInOutDetailRptQueryEntity.SortDirection = "ASC";
                }
                this.BindData2ImportDeclarationsRptList(declarationsInOutDetailRptQueryEntity);
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        private void LoadData()
        {
            DeclarationsInOutDetailRptQueryEntity declarationsInOutDetailRptQueryEntity = new DeclarationsInOutDetailRptQueryEntity();
            if (string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                if (this.PreviousPage != null)
                {
                    declarationsInOutDetailRptQueryEntity.DeclarationsID = this.PreviousPage.DeclarationsID;
                    declarationsInOutDetailRptQueryEntity.OwnerID = this.PreviousPage.OwnerID;
                    declarationsInOutDetailRptQueryEntity.SkuID = this.PreviousPage.SkuID;
                    declarationsInOutDetailRptQueryEntity.CompanyDeclarationgsID = this.PreviousPage.CompanyDeclarationsID;
                    declarationsInOutDetailRptQueryEntity.DeclarationsDate = this.PreviousPage.DeclarationsDate;
                }
                else
                {
                    declarationsInOutDetailRptQueryEntity.DeclarationsID = "";
                    declarationsInOutDetailRptQueryEntity.OwnerID = "";
                    declarationsInOutDetailRptQueryEntity.SkuID = "";
                    declarationsInOutDetailRptQueryEntity.CompanyDeclarationgsID = "";
                    declarationsInOutDetailRptQueryEntity.VerificationFormID = "";
                    declarationsInOutDetailRptQueryEntity.DeclarationsDate = "";
                }
            }
            else
            {
                this.hdnFrom.Value = base.Request.QueryString["from"].ToString();
            }
            declarationsInOutDetailRptQueryEntity.IsGetAll = false;
            declarationsInOutDetailRptQueryEntity.CurrentPage = "0";
            declarationsInOutDetailRptQueryEntity.PageSize = this.gvDeclarationsInOutDetailRpt.PageSize.ToString();
            declarationsInOutDetailRptQueryEntity.SortField = " A.IN_DECLARATIONS_ID,A.SKU_ID,EDD.DECLARATIONS_ID";
            declarationsInOutDetailRptQueryEntity.SortDirection = "DESC";
            this.PagerFooter.PageSize = this.gvDeclarationsInOutDetailRpt.PageSize;
            if (!string.IsNullOrEmpty(base.Request.QueryString["export"]))
            {
                this.hdnActionID.Value = base.Request.QueryString["export"];
            }
            this.SetDeclarationsInOutDetailRptQueryEntity(declarationsInOutDetailRptQueryEntity);
            this.BindData2ImportDeclarationsRptList(declarationsInOutDetailRptQueryEntity);
            if (!string.IsNullOrEmpty(base.Request.QueryString["export"]))
            {
                this.btnExport_Click(null, null);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
            }
        }

        private void SetDeclarationsInOutDetailRptQueryEntity(DeclarationsInOutDetailRptQueryEntity declarationsInOutDetailRptQueryEntity)
        {
            if (!string.IsNullOrEmpty(this.hdnActionID.Value))
            {
                base.PageQueryEntityViewState = declarationsInOutDetailRptQueryEntity;
            }
            else
            {
                base.PageQueryEntitySession = declarationsInOutDetailRptQueryEntity;
            }
        }

        public DeclarationsInOutDetailRptQuery PreviousPage
        {
            get
            {
                return (DeclarationsInOutDetailRptQuery) base.PreviousPage;
            }
        }
    }
}

